import { Router } from 'express';
import { authenticateToken } from '@/middleware/auth';
import { NotesController } from '@/controllers/notes';
import { uploadMemorySingle } from '@/utils/upload';

const router = Router();

/* 分组 */
router.get('/groups', authenticateToken, NotesController.listGroups);
router.post('/groups', authenticateToken, NotesController.createGroup);
router.patch('/groups/:id', authenticateToken, NotesController.renameGroup);
router.delete('/groups/:id', authenticateToken, NotesController.deleteGroup);
// 共享
router.post('/groups/:id/share', authenticateToken, NotesController.shareGroup);
router.delete('/groups/:id/share/:userId', authenticateToken, NotesController.unshareGroup);

// 便签
router.get('/', authenticateToken, NotesController.listNotes);
router.post('/', authenticateToken, NotesController.createNote);
router.patch('/:id', authenticateToken, NotesController.updateNote);
router.delete('/:id', authenticateToken, NotesController.deleteNote);

// 计时
router.post('/:id/time', authenticateToken, NotesController.addTime);

// 附件（本地上传，后续可切对象存储）
router.post('/:id/attachments', authenticateToken, uploadMemorySingle('file'), NotesController.uploadAttachment);
router.get('/:id/attachments', authenticateToken, NotesController.listAttachments);
router.delete('/attachments/:attachmentId', authenticateToken, NotesController.deleteAttachment);

export const notesRoutes = router;
export default router;